package com.itheima.dao;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户的持久层接口
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 */
public interface IUserDao {

    /**
     * 查询用户列表
     */
    @Select("select * from user")
    List<User> findAll();

    /**
     * 根据id查询
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId} ")
    User findById(Integer userId);

    /**
     * 更新用户
     * @param user
     */
    @Update("update user set username=#{username},password=#{password},age=#{age},sex=#{sex},email=#{email} where id=#{id}")
    void updateUser(User user);
    /**
     * 删除用户
     * @param userId
     */
    @Delete("delete from user where id = #{userId}")
    void deleteById(Integer userId);
    /**
     * 增加用户
     * @param user
     */
    @Insert("INSERT INTO `user`(age,username,password,email,sex) VALUES ( #{age}, #{username},#{password}, #{email}, #{sex})")
    void insertUser(User user);
}
